/**
 * 不同模式下推荐devtool配置
 * 1.开发模式下 eval-cheap-module-source-map
 *   (1)代码每行不超过80个字符
 *   (2)代码警告Loader转换过后的差异较大
 *   (3)首次打包速度慢无所谓，重写打包相对较快
 * 2.生产环境下 none
 *   (1)Source Map会暴露源代码
 *   
 * 
 */ 

// devtool配置
const allModus = [
  'eval',
  'eval-cheap-source-map',
  'eval-cheap-module-source-map',
  'eval-source-map',
  'cheap-source-map',
  'cheap-module-source-map',
  'source-map',
  'inline-cheap-source-map',
  'inline-cheap-module-source-map',
  'inline-source-map',
  'eval-nosources-cheap-source-map',
  'eval-nosources-cheap-module-source-map',
  'eval-nosources-source-map',
  'inline-nosources-cheap-source-map',
  'inline-nosources-cheap-module-source-map',
  'inline-nosources-source-map',
  'nosources-cheap-source-map',
  'nosources-cheap-module-source-map',
  'nosources-source-map',
  'hidden-nosources-cheap-source-map',
  'hidden-nosources-cheap-module-source-map',
  'hidden-nosources-source-map',
  'hidden-cheap-source-map',
  'hidden-cheap-module-source-map',
  // 'hidden-source-map,'
]

const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

module.exports = allModus.map((item) => {
  return {
    devtool: item,
    mode: 'none',
    entry: './src/main.js',
    output: {
      filename: `js/${item}.js`
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env']
            }
          }
        }
      ]
    },
    plugins: [
      // 打包前清空dist目录
      new CleanWebpackPlugin(),
      new HtmlWebpackPlugin({
        filename: `${item}.html`
      })
    ]
  }
})

// module.exports = [
//   {
//     entry: './src/main.js',
//     output: {
//       filename: 'a.js'
//     }
//   },
//   {
//     entry: './src/main.js',
//     output: {
//       filename: 'b.js'
//     }
//   }
// ]